<template>
  <view class="pages">
    <!-- #ifdef APP-PLUS-->
    <u-sticky offset-top="0" zIndex="10000">
    <!-- #endif -->
      <!-- #ifdef H5 -->
      <u-sticky offset-top="-44" zIndex="10000">
      <!-- #endif -->
      <view class="followTop">
        <up-navbar
          title="简介/擅长"
          :placeholder="true"
          @rightClick="rightClick"
          :autoBack="true"
        >
          <template #right>
            <view class="btn">保存</view>
          </template>
        </up-navbar>
      </view>
      </u-sticky>
    <view class="content">
      <view style="border-bottom: 20rpx solid #f6f6f6"></view>
      <up-textarea
        v-model="autograph"
        placeholder="请输入个人简介/擅长"
        height="350rpx"
        border="none"
        :focus="true"
        :autoHeight="false"
        maxlength="200"
      ></up-textarea>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { showToast,navigateBack } from '@/utils'
import { useMemberStore } from '@/stores'
import { doctorInfo } from '@/api/home'
import { updateDoctorInfo } from '@/api/my'
const userStore = useMemberStore()

const autograph = ref('')
const type = ref('')
onLoad((options) => {
  if(options.type == 'edit') {
	  type.value = options.type
	}else if(options.type == 'open') {
	  type.value = options.type
	}
	if(options.text) {
	  autograph.value=options.text||""
	}else{
		getDoctorInfo()
	}
  
})
async function getDoctorInfo() {
  const res = await doctorInfo()
  autograph.value = res.data.adept
}
async function rightClick() {
  // 1=修改医院名称2=修改科室名称3=修改职称4=修改头像5=修改擅长6=修改标签
  
	if(type.value == 'open') {
		if(autograph.value){
			navigateBack()
			uni.$emit('updateGraph', autograph.value)
		}else{
			showToast('请输入简介/擅长')
		}
		return false;
	}
  if(type.value == 'edit') {
    if(!autograph.value) {
      uni.showToast({
        title:'简介/擅长不能为空',
        icon: 'none',
      }) 
      return
    }else {
      const params = {
        adept: autograph.value,
        type: 5,
      }
      const res = await updateDoctorInfo(params)
      if (res.code == 200) {
        uni.$emit('updateUserInfo')
        uni.navigateBack({
          delta: 1,
        })
      }
      if(res.code == 500) {
        uni.showToast({
          title:res.message,
          icon: 'none',
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.pages {
  min-height: 100vh;
  width: 100%;
  background-color: #f5f6f8;
  .followTop {
    width: 100%;
    background: #fff
  }
  .btn {
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 30rpx;
    color: #00c1b9;
  }
  .content {
    width: 702rpx;
    height: 400rpx;
    background: #ffffff;
    border-radius: 40rpx 40rpx 20rpx 20rpx;
    margin: 0 auto;
  }
}
</style>
